
#ifndef __BOARD_H__
#define __BOARD_H__

#ifdef __cplusplus
extern "C" {
#endif

#include <stdint.h>

/* board init*/
const char *driv_get_board(void);
int driv_board_init(int is_app);
int driv_board_deinit(int is_app);

/* cpu reboot & jump to app */
void driv_cpu_reboot(uint32_t ms);
void driv_cpu_reboot_check(void);
void driv_jump_to_app(uint32_t address);
uint32_t driv_disable_irq(void);
void driv_enable_irq(uint32_t flag);

/* hardware delay us */
int hw_delay_init(void);
int hw_delay_us(uint32_t us); // us should be less than 1000
int hw_delay_ms(uint32_t ms);

/* systick ticks */
uint32_t driv_tick_get(void);
void driv_tick_inc(void);
uint32_t driv_tick_elaps(uint32_t prev_tick);

/* timer_adc */
#define ADC_CHANNEL_NUM  5
int driv_timer_adc_init(void);
/* adc_get_value
    * adc_value: array of adc value, length is ADC_CHANNEL_NUM
    * return: 0 - success, -1 - fail
    * note: the value's unit is mV(0 ~ 65535)
*/
int driv_adc_get_value(uint16_t* adc_value);
/* timer_pwm_set
    * pwm_value: 0 ~ 10000
    * return: 0 - success, -1 - fail
    * note: pwm_value = 10000 means 100% duty cycle
    *      pwm_value = 0 means 0% duty cycle
*/
int driv_timer_pwm_set(uint16_t pwm_value);

/* run status led */
int driv_run_led_init(void);
int driv_run_led_op(int on_off);

/* flash table */
#if EV_BOARD_N32G45XVL_STB
    #define BOOT_BASE       0x08000000
    #define BOOT_SIZE       (64 * 1024)
    #define APP1_BASE       (BOOT_BASE + BOOT_SIZE)
    #define APP1_SIZE       ((512 * 1024 - BOOT_SIZE) / 2)
    #define APP2_BASE       (APP1_BASE + APP1_SIZE)
    #define APP2_SIZE       (APP1_SIZE)
#elif EV_BOARD_QIMIN407
    #define BOOT_BASE       0x08000000
    #define BOOT_SIZE       (64 * 1024)
    #define APP1_BASE       (BOOT_BASE + BOOT_SIZE)
    #define APP1_SIZE       (512 * 1024 - BOOT_SIZE)
    #define APP2_BASE       (APP1_BASE + APP1_SIZE)
    #define APP2_SIZE       (APP1_SIZE)
#else
    #error "Please select a board!"
#endif

/* flash operation */
int ota_flash_get_sector(uint32_t addr);
int ota_flash_check_align(uint32_t addr);
int ota_flash_erase(uint32_t addr, uint32_t length);
int ota_flash_write(uint32_t addr, const uint8_t* data, uint32_t len);


/* console uart */
int driv_console_uart_init(uint32_t baudrate);
void driv_console_uart_tx_cb(void);
void driv_console_uart_rx_cb(uint8_t c);
int driv_console_uart_write(const uint8_t* data, uint32_t len); // none block

/* trans uart */
int driv_trans_uart_init(uint32_t baudrate);
void driv_trans_uart_tx_cb(void);
void driv_trans_uart_rx_cb(uint8_t c);
int driv_trans_uart_write(const uint8_t* data, uint32_t len); // none block


#ifdef __cplusplus
}
#endif

#endif /* __BOARD_H__ */


